/*
 * @Description: 路由配置文件
 * @Version: 2.0
 * @Autor: lhl
 * @Date: 2021-06-09 21:34:13
 * @LastEditors: lhl
 * @LastEditTime: 2021-06-19 20:59:54
 */
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import Home from 'Components/layout/index.vue'
const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    redirect: '/Dashboard'
  },
  {
    path: '/',
    name: 'Home',
    component: Home,
    children: [
      {
        path: '/Dashboard',
        name: 'Dashboard',
        meta: {
          title: '首页'
        },
        component: () => import(/* webpackChunkName: "Dashboard" */ 'View/dashboard/index.vue')
      },
      {
        path: '',
        name: 'SysConfigList',
        meta: {
          title: '系统设置'
        },
        component: () => import(/* webpackChunkName: "viewOutPut" */ 'View/viewOutPut/index.vue'),
        children: [
          {
            path: '/ModuleConfigList',
            name: 'ModuleConfigList',
            meta: {
              title: '模块设置'
            },
            component: () => import(/* webpackChunkName: "ModuleConfigList" */ 'View/sysConfig/ModuleConfigList.vue')
          },
          {
            path: '/RoleConfigList',
            name: 'RoleConfigList',
            meta: {
              title: '角色管理'
            },
            component: () => import(/* webpackChunkName: "RoleConfigList" */ 'View/sysConfig/RoleConfigList.vue')
          },
          {
            path: '/MenuConfig',
            name: 'MenuConfig',
            meta: {
              title: '菜单管理'
            },
            component: () => import(/* webpackChunkName: "MenuConfig" */ 'View/sysConfig/MenuConfig.vue')
          }
        ]
      },
      {
        path: '',
        name: 'shopConfigList',
        meta: {
          title: '商品设置'
        },
        component: () => import(/* webpackChunkName: "viewOutPut" */ 'View/viewOutPut/index.vue'),
        children: [
          {
            path: '/PutOnConfigList',
            name: 'PutOnConfigList',
            meta: {
              title: '上架设置'
            },
            component: () => import(/* webpackChunkName: "PutOnConfigList" */ 'View/shopConfig/PutOnConfigList.vue')
          },
          {
            path: '/GoOnConfigList',
            name: 'GoOnConfigList',
            meta: {
              title: '下架设置'
            },
            component: () => import(/* webpackChunkName: "GoOnConfigList" */ 'View/shopConfig/GoOnConfigList.vue')
          },
          {
            path: '',
            name: 'ModifyPrice',
            meta: {
              title: '调价设置'
            },
            component: () => import(/* webpackChunkName: "viewOutPut" */ 'View/viewOutPut/index.vue'),
            children: [
              {
                path: '/RiseRriceList',
                name: '/RiseRriceList',
                meta: {
                  title: '涨价设置'
                },
                component: () => import(/* webpackChunkName: "RiseRriceList" */ 'View/shopConfig/modifyPrice/RiseRriceList.vue')
              },
              {
                path: '/CutPriceList',
                name: 'CutPriceList',
                meta: {
                  title: '降价设置'
                },
                component: () => import(/* webpackChunkName: "CutPriceList" */ 'View/shopConfig/modifyPrice/CutPriceList.vue')
              }
            ]
          }
        ]
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    meta: {
      title: '登录'
    },
    component: () => import('@/view/login/index.vue')
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/view/notFound/index.vue')
  },
  {
    path: '/:pathMatch(.*)', // 和以前配置有所不一样 or  /:catchAll(.*)
    redirect: '/404'
  }
]
const router = createRouter({
  history: createWebHashHistory(),
  routes
})

// console.log(router, 'router')
// 路由前置钩子
router.beforeEach((to, from, next) => {
  // console.log(from, 'from')
  const title = to.meta && (to.meta.title as string)
  if (title) {
    document.title = title
  }
  next()
})

router.afterEach((to, from) => {
  // console.log(to, 'to', from, 'from')
})

// 路由配置上定义 路由独享的守卫
// beforeEnter: (to, from) => {
//   // reject the navigation
//   return false
// },

// 导航守卫
// onBeforeRouteLeave, onBeforeRouteUpdate

export default router
